#include "GameTimer.h"

#include <Windows.h>

std::unique_ptr<GameTimer> gpTimer;

GameTimer::GameTimer()
{
	__int64 countsPerSec;
	QueryPerformanceFrequency( (LARGE_INTEGER*)&countsPerSec );
	mSecondsPerCount = 1.0 / (double)countsPerSec;

	mTime = 0;
	mDeltaTime = 0;

	mCurrTime = 0;
	mPrevTime = 0;
}

GameTimer::~GameTimer()
{

}

void GameTimer::Tick()
{
	QueryPerformanceCounter( (LARGE_INTEGER*)&mCurrTime );
	mTime = (mCurrTime - mBaseTime) * mSecondsPerCount;
	mDeltaTime = (mCurrTime - mPrevTime) * mSecondsPerCount;

	if( mDeltaTime < 0.0 )
	{
		mDeltaTime = 0.0;
	}
}

void GameTimer::Reset()
{
	mPrevTime = mCurrTime;
}

void GameTimer::SetBaseTime()
{
	QueryPerformanceCounter( (LARGE_INTEGER*)&mBaseTime );
	mCurrTime = mBaseTime;
}